<?php

class PembayaranSetoranBankController extends Controller {

    /**
     * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
     * using two-column layout. See 'protected/views/layouts/column2.php'.
     */
    public $layout = '//layouts/column1';
    public $title = 'Entry Data Pembayaran Melalui Bank';

    /**
     * @return array action filters
     */
    public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }

    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * @return array access control rules
     */
    public function accessRules() {
        return array(
            array('allow', // allow all users to perform 'index' and 'view' actions
                'actions' => array('index', 'view','Loadcities','PopUp','verifikasi'),
                'users' => array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions' => array('create', 'update','Loadcities','PopUp','verifikasi'),
                'users' => array('@'),
            ),
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions' => array('admin', 'delete','Loadcities','PopUp','verifikasi'),
                'users' => array('admin'),
            ),
            array('deny', // deny all users
                'users' => array('*'),
            ),
        );
    }

    /**
     * Displays a particular model.
     * @param integer $id the ID of the model to be displayed
     */
    public function actionView($id) {
        $this->render('view', array(
            'model' => $this->loadModel($id),
            'asd' => $id,
        ));
    }

    /**
     * Creates a new model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     */
     
     public function actionLoadcities() {

        $kode_kec = $_POST['haha'];
        $kelurahans = RefKelurahan::model()->findAll(array("condition" => "kd_kecamatan='$kode_kec'", "order" => "kd_kelurahan"));

        $i=0;
        //var_dump($kelurahans[0]['kd_kelurahan']);
        
        foreach ($kelurahans as $kelurahan):
            $data[$i] = $kelurahan->kd_kelurahan.'-'.$kelurahan->nm_kelurahan;
            //$data[$i]['kode'] = $kelurahan->kd_kelurahan;
        $i++;
        endforeach;
        //var_dump($data);
    echo json_encode($data);
        if ($data != null) {
            //echo CHtml::tag('option', array('value' => ""), CHtml::encode("Kode - Kelurahan"), true);
            foreach ($data as $value => $name) {
              //  echo CHtml::tag('option', array('value' => $value), CHtml::encode($name), true);
            }
        } else {
            //echo CHtml::tag('option', array('value' => ''), CHtml::encode('Kelurahan Belum Tersedia'), true);
        }
    }

     
     
     public function actionPopUp(){
        $modelDokTerima= new DokTerima ;
        
        
    
        $this->renderPartial('PopUp', array(
            'modelDokTerima' => $modelDokTerima,
        ));
        
     }
     
     
    public function actionCreate() {

            
        $model = new ObjekPajak;
        $modelSetoran = new Setoran;
        $modelWajibPajak = new WajibPajak;
        $modelSk = new Sk;
        $modelDatSubjekPajak = new DatSubjekPajak;
        
        $modelDatSubjekPajak->unsetAttributes(); 
        if(isset($_GET['DatSubjekPajak'])){
            $modelDatSubjekPajak->attributes = $_GET['DatSubjekPajak'];
            //$model->nm_wp = $_GET['DatSubjekPajak']['nm_wp'];
	}
        
        
           if(isset($_GET['ObjekPajak'])){
            $model->attributes = $_GET['ObjekPajak'];
            $model->nm_wp = $_GET['ObjekPajak']['nm_wp'];
	}

                $modelSetoran->unsetAttributes();  // clear any default values
                if (isset($_POST['Setoran'])) {
   
                 
         

            $sCekPbb="select array_to_string(array(select thn_pajak_sppt from pbb.sppt where
            kd_propinsi='".$_POST['Setoran']['kd_propinsi']."' and
            kd_dati2='".$_POST['Setoran']['kd_dati2']."' and
            kd_kecamatan='".$_POST['Setoran']['kd_kecamatan']."' and
            kd_kelurahan='".$_POST['Setoran']['kd_kelurahan']."' and
            kd_blok='".$_POST['Setoran']['kd_blok']."' and
            no_urut='".$_POST['Setoran']['no_urut']."' and
            kd_jns_op='".$_POST['Setoran']['kd_jns_op']."' and to_number(thn_pajak_sppt, '9999') > extract(year from now())-5
            and status_pembayaran_sppt = '0'), ', ') as thn_pajak_sppt";
			
			$cekPbb = Yii::app()->db->createCommand($sCekPbb)->queryRow();
			
            
            if($cekPbb == 0){
                $modelSetoran->addError('kd_propinsi', "Nop ".$_POST['Setoran']['kd_propinsi'].$_POST['Setoran']['kd_dati2'].$_POST['Setoran']['kd_kecamatan'].$_POST['Setoran']['kd_kelurahan'].$_POST['Setoran']['kd_blok'].$_POST['Setoran']['no_urut'].$_POST['Setoran']['kd_jns_op']." Memiliki Tunggakan PBB Pada Tahun ".$cekPbb['thn_pajak_sppt']);
            }
            else {
            $CountNik = count(DatSubjekPajak::model()->findAll("subjek_pajak_id='".$_POST['Setoran']['nik_wp'] . "'"));
            $CountJenis = $_POST['Setoran']['jenis_sk'];
            //if($CountJenis !='01')            
            
            if ($CountNik >= 1 && $CountJenis =='01') {

                $modelSetoran = new Setoran;
                
             $query = "select max(nomor) as nomor from bphtb.setoran";
             $hasil = Yii::app()->db->createCommand($query)->queryRow();
             $nomor=$hasil['nomor']+1;
            
    
   			$rsKode = Sptpd::model()->findBySql("select kode_sptpd from bphtb.sptpd where nik_wp = '".$_POST["Setoran"]["nik_wp"]."'");
			$cKode = count($rsKode);
            $modelSetoran->nomor=$nomor;
            $modelSetoran->no_bayar = str_pad($nomor, 6, '0', STR_PAD_LEFT);
			$modelSetoran->kode_sptpd = ($cKode >=1)?$rsKode['kode_sptpd']:0; //Inline IF
                $modelSetoran->thn_pajak = $_POST['Setoran']['thn_pajak'];
                $modelSetoran->pajak_bphtb = 0;
                $modelSetoran->tgl_bayar =HelperUtils::tglToDb($_POST["Setoran"]["tgl_bayar"]); 
                $modelSetoran->nik_wp = trim($_POST['Setoran']['nik_wp']);
                $modelSetoran->no_rev = $_POST['Setoran']['no_rev'];
$modelSetoran->jml_bayar = substr(str_replace('.', '', $_POST['Setoran']['jml_bayar']), 0, strlen(str_replace('.', '', $_POST['Setoran']['jml_bayar'])) - 3);
                $modelSetoran->kode_vib = 1;
                $modelSetoran->jenis_sk = $_POST['Setoran']['jenis_sk'];
                $modelSetoran->kd_propinsi = $_POST['Setoran']['kd_propinsi'];
                $modelSetoran->kd_dati2 = $_POST['Setoran']['kd_dati2'];
                $modelSetoran->kd_kecamatan = $_POST['Setoran']['kd_kecamatan'];
                $modelSetoran->kd_kelurahan = $_POST['Setoran']['kd_kelurahan'];
                $modelSetoran->kd_blok = $_POST['Setoran']['kd_blok'];
                $modelSetoran->no_urut = $_POST['Setoran']['no_urut'];
                $modelSetoran->kd_jns_op = $_POST['Setoran']['kd_jns_op'];
                $modelSetoran->sts = 0;

                $transaction = Yii::app()->db->beginTransaction();
                //$transaction->commit();
                try {


                    if ($modelSetoran->save()) {
                        
                         
                        $bayar = NomorSk::model()->find();
                        $test = $bayar->bayar + 1;
                        $query = "UPDATE bphtb.nomor_sk SET bayar='" . $test . "'";

                        $command = Yii::app()->db->createCommand($query);
                        $command->execute();
                        $transaction->commit();
                        Yii::app()->user->setFlash('success', '<strong>Selamat !!</strong> Data telah berhasil disimpan.');
                        $this->redirect(array('create',

                        ));

                    }
                    else{
                    $modelSetoran->tgl_bayar ="";
                 }

                    }
                    
                     catch (Exception $e) {
                    $transaction->rollback();
                    throw new CHttpException(400, $e->getMessage());
                }
            } 
            
            else if($CountJenis !='01'){
                            
             $modelSetoran = new Setoran;
             $query = "select max(nomor) as nomor from bphtb.setoran";
             $hasil = Yii::app()->db->createCommand($query)->queryRow();
             $nomor=$hasil['nomor']+1;
            
            $query2 = Sptpd::model()->findAll();
            
            
            $Sql="select kode_sptpd from bphtb.sptpd where kode_sptpd='".$_POST['Setoran']['kode_sptpd']."'";        
			$cc = Yii::app()->db->createCommand($Sql)->queryRow();
            $aa = $cc['kode_sptpd'];
            
       
            $modelSetoran->nomor=$nomor;
            $modelSetoran->no_bayar = str_pad($nomor, 6, '0', STR_PAD_LEFT);
			//$modelSetoran->kode_sptpd = $_POST['Setoran']['kode_sptpd']; //Inline IF
                $modelSetoran->kode_sptpd = $aa; //Inline IF
                $modelSetoran->thn_pajak = $_POST['Setoran']['thn_pajak'];
                $modelSetoran->pajak_bphtb = 0;
                $modelSetoran->tgl_bayar =HelperUtils::tglToDb($_POST["Setoran"]["tgl_bayar"]); 
                $modelSetoran->nik_wp = trim($_POST['Setoran']['nik_wp']);
                $modelSetoran->no_rev = $_POST['Setoran']['no_rev'];
                $modelSetoran->jml_bayar = substr(str_replace('.', '', $_POST['Setoran']['jml_bayar']), 0, strlen(str_replace('.', '', $_POST['Setoran']['jml_bayar'])) - 3);
                $modelSetoran->kode_vib = 1;
                $modelSetoran->jenis_sk = $_POST['Setoran']['jenis_sk'];
                $modelSetoran->kd_propinsi = $_POST['Setoran']['kd_propinsi'];
                $modelSetoran->kd_dati2 = $_POST['Setoran']['kd_dati2'];
                $modelSetoran->kd_kecamatan = $_POST['Setoran']['kd_kecamatan'];
                $modelSetoran->kd_kelurahan = $_POST['Setoran']['kd_kelurahan'];
                $modelSetoran->kd_blok = $_POST['Setoran']['kd_blok'];
                $modelSetoran->no_urut = $_POST['Setoran']['no_urut'];
                $modelSetoran->kd_jns_op = $_POST['Setoran']['kd_jns_op'];
                $modelSetoran->sts = 1;

                $transaction = Yii::app()->db->beginTransaction();
                //$transaction->commit();
                try {


                    if ($modelSetoran->save()) {
                        
                         
                        $bayar = NomorSk::model()->find();
                        $test = $bayar->bayar + 1;
                        $query = "UPDATE bphtb.nomor_sk SET bayar='" . $test . "'";
                        $command = Yii::app()->db->createCommand($query);
                        $command->execute();
                        
                        
                        //$query2 = "update bphtb.sptpd set kode_sptpd =1 where kode_sptpd ='" . $test . "'"";
                        $query2 = "UPDATE bphtb.sptpd SET sts_bayar=1 where kode_sptpd = '".$modelSetoran->kode_sptpd."'";
                        $command = Yii::app()->db->createCommand($query2);
                        $command->execute();
                        //print_r($modelSetoran->save());
                        
                        //exit();
                        
                        $transaction->commit();
                        Yii::app()->user->setFlash('success', '<strong>Selamat !!</strong> Data telah berhasil disimpan.');
                        $this->redirect(array('create',

                        ));

                    }
                   // else{
                    //$modelSetoran->tgl_bayar ="";
                 //}

                    } catch (Exception $e) {
                    $transaction->rollback();
                    throw new CHttpException(404, $e->getMessage());
                }
            } 
             else {
                $modelInsertDatSubjekPajak = new DatSubjekPajak;

                $modelWajibPajak = new WajibPajak;

                $modelWajibPajak->subjek_pajak_id = trim($_POST['Setoran']['nik_wp']);
                $modelWajibPajak->nama_kec = $_POST['WajibPajak']['nama_kec'];

                $modelInsertDatSubjekPajak->subjek_pajak_id = trim($_POST['Setoran']['nik_wp']);
                $modelInsertDatSubjekPajak->nm_wp = $_POST['DatSubjekPajak']['nm_wp'];
                $modelInsertDatSubjekPajak->jalan_wp = $_POST['DatSubjekPajak']['jalan_wp'];
                $modelInsertDatSubjekPajak->blok_kav_no_wp = $_POST['DatSubjekPajak']['blok_kav_no_wp'];
                $modelInsertDatSubjekPajak->rt_wp = $_POST['DatSubjekPajak']['rt_wp'];
                $modelInsertDatSubjekPajak->rw_wp = $_POST['DatSubjekPajak']['rw_wp'];
                $modelInsertDatSubjekPajak->kd_pos_wp = $_POST['DatSubjekPajak']['kd_pos_wp'];
                $modelInsertDatSubjekPajak->kota_wp = $_POST['DatSubjekPajak']['kota_wp'];


             $modelSetoran = new Setoran;
             $query = "select max(nomor) as nomor from bphtb.setoran";
             $hasil = Yii::app()->db->createCommand($query)->queryRow();
             $nomor=$hasil['nomor']+1;
            
    
				$modelSetoran->nomor=$nomor;
				$modelSetoran->no_bayar = str_pad($nomor, 6, '0', STR_PAD_LEFT);
				$modelSetoran->kode_sptpd = 0;
                $modelSetoran->thn_pajak = $_POST['Setoran']['thn_pajak'];
                $modelSetoran->pajak_bphtb = 0;
                $modelSetoran->tgl_bayar =HelperUtils::tglToDb($_POST["Setoran"]["tgl_bayar"]); 
                $modelSetoran->nik_wp = trim($_POST['Setoran']['nik_wp']);
                $modelSetoran->no_rev = $_POST['Setoran']['no_rev'];
                $modelSetoran->jml_bayar = substr(str_replace('.', '', $_POST['Setoran']['jml_bayar']), 0, strlen(str_replace('.', '', $_POST['Setoran']['jml_bayar'])) - 3);
                $modelSetoran->kode_vib = 1;
                $modelSetoran->jenis_sk = $_POST['Setoran']['jenis_sk'];
                $modelSetoran->kd_propinsi = $_POST['Setoran']['kd_propinsi'];
                $modelSetoran->kd_dati2 = $_POST['Setoran']['kd_dati2'];
                $modelSetoran->kd_kecamatan = $_POST['Setoran']['kd_kecamatan'];
                $modelSetoran->kd_kelurahan = $_POST['Setoran']['kd_kelurahan'];
                $modelSetoran->kd_blok = $_POST['Setoran']['kd_blok'];
                $modelSetoran->no_urut = $_POST['Setoran']['no_urut'];
                $modelSetoran->kd_jns_op = $_POST['Setoran']['kd_jns_op'];
                $modelSetoran->sts = 0;
                $transaction = Yii::app()->db->beginTransaction();
                
                try {


                    if ($modelSetoran->save() && $modelInsertDatSubjekPajak->save() && $modelWajibPajak->save()) {

                        // Yii::app()->user->setFlash('success', "Data saved!");
                        $bayar = NomorSk::model()->find();
                        $test = $bayar->bayar + 1;
                        $query = "UPDATE nomor_sk SET bayar='" . $test . "'";

                        $command = Yii::app()->db->createCommand($query);
                        $command->execute();
						$transaction->commit();
						Yii::app()->user->setFlash('success', '<strong>Selamat !!</strong> Data telah berhasil disimpan.');

                        $this->redirect(array('create',
//                        'message'=>'Success',
                        ));
                        //$this->redirect(array('create'));
                    }
                    else{
                    $modelSetoran->tgl_bayar ="";
                 }
                } catch (Exception $e) {
                    $transaction->rollback();
                    throw new CHttpException(400, $e->getMessage());
                }
            }
         }
        }

        $this->render('create', array(
            'model' => $model,
            'modelWajibPajak' => $modelWajibPajak,
            'modelSetoran' => $modelSetoran,
            'modelSk' => $modelSk,
            'modelDatSubjekPajak' => $modelDatSubjekPajak,
            
        ));
    }

    /**
     * Updates a particular model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id the ID of the model to be updated
     */
    public function actionUpdate($id) {
        $modelSetoran = $this->loadModel($id);
        $model = new ObjekPajak;
        $modelWajibPajak = new WajibPajak;
        $modelSk = new Sk;
        $modelDatSubjekPajak = new DatSubjekPajak;
        $modelDatSubjekPajak->nm_wp = $modelSetoran->nm_wp;
        $modelDatSubjekPajak->jalan_wp = $modelSetoran->jalan_wp;
        $modelDatSubjekPajak->blok_kav_no_wp = $modelSetoran->blok_kav_no_wp;
        $modelDatSubjekPajak->nama_kec = $modelSetoran->nama_kec;
        $modelDatSubjekPajak->kelurahan_wp = $modelSetoran->kelurahan_wp;
        $modelDatSubjekPajak->rt_wp = $modelSetoran->rt_wp;
        $modelDatSubjekPajak->rw_wp = $modelSetoran->rw_wp;
        $modelDatSubjekPajak->kd_pos_wp = $modelSetoran->kd_pos_wp;
        $modelDatSubjekPajak->kota_wp = $modelSetoran->kota_wp;
        $modelSetoran->tgl_bayar = date("d/m/Y", strtotime($modelSetoran->tgl_bayar));
        
        
        
        if(isset($_GET['DatSubjekPajak'])){
        $modelDatSubjekPajak->subjek_pajak_id = $_GET['DatSubjekPajak']['subjek_pajak_id'];
        $modelDatSubjekPajak->nm_wp = $_GET['DatSubjekPajak']['nm_wp'];
    }    
        if(isset($_GET['ObjekPajak'])){
            $model->attributes = $_GET['ObjekPajak'];
            $model->nm_wp = $_GET['ObjekPajak']['nm_wp'];
    }
    
         // clear any default values
                if (isset($_POST['Setoran'])) {
            
            $CountNik = count(DatSubjekPajak::model()->findAll("subjek_pajak_id='".$_POST['Setoran']['nik_wp'] . "'"));
            $CountJenis = $_POST['Setoran']['jenis_sk'];
            //if($CountJenis !='01')            
            
            if ($CountNik >= 1 && $CountJenis =='01') {

     		$rsKode = Sptpd::model()->findBySql("select kode_sptpd from bphtb.sptpd where nik_wp = '".$_POST["Setoran"]["nik_wp"]."'");
			$cKode = count($rsKode);
        
            $modelSetoran->attributes=$_POST['Setoran'];    
            
			$modelSetoran->kode_sptpd = ($cKode >=1)?$rsKode['kode_sptpd']:0; //Inline IF
                $modelSetoran->thn_pajak = $_POST['Setoran']['thn_pajak'];
                $modelSetoran->pajak_bphtb = 0;
                $modelSetoran->tgl_bayar =HelperUtils::tglToDb($_POST["Setoran"]["tgl_bayar"]); 
                $modelSetoran->nik_wp = trim($_POST['Setoran']['nik_wp']);
                //$modelSetoran->no_rev = $_POST['Setoran']['no_rev'];
$modelSetoran->jml_bayar = substr(str_replace('.', '', $_POST['Setoran']['jml_bayar']), 0, strlen(str_replace('.', '', $_POST['Setoran']['jml_bayar'])) - 3);
                $modelSetoran->kode_vib = 1;
                $modelSetoran->jenis_sk = $_POST['Setoran']['jenis_sk'];
                $modelSetoran->kd_propinsi = $_POST['Setoran']['kd_propinsi'];
                $modelSetoran->kd_dati2 = $_POST['Setoran']['kd_dati2'];
                $modelSetoran->kd_kecamatan = $_POST['Setoran']['kd_kecamatan'];
                $modelSetoran->kd_kelurahan = $_POST['Setoran']['kd_kelurahan'];
                $modelSetoran->kd_blok = $_POST['Setoran']['kd_blok'];
                $modelSetoran->no_urut = $_POST['Setoran']['no_urut'];
                $modelSetoran->kd_jns_op = $_POST['Setoran']['kd_jns_op'];
                $modelSetoran->sts = 0;

                $transaction = Yii::app()->db->beginTransaction();
                //$transaction->commit();
                try {


                    if ($modelSetoran->save()) {
                        $transaction->commit();
                        Yii::app()->user->setFlash('success', '<strong>Selamat !!</strong> Data telah berhasil diupdate.');
                        $this->redirect(array('create',

                        ));

                    }

                    } catch (Exception $e) {
                    $transaction->rollback();
                    throw new CHttpException(400, $e->getMessage());
                }
            } 
            
            else if($CountJenis !='01'){
                            
            $modelSetoran->attributes=$_POST['Setoran']; 
            
			$modelSetoran->kode_sptpd = $_POST['Setoran']['kode_sptpd']; //Inline IF
                $modelSetoran->thn_pajak = $_POST['Setoran']['thn_pajak'];
                $modelSetoran->pajak_bphtb = 0;
                $modelSetoran->tgl_bayar =HelperUtils::tglToDb($_POST["Setoran"]["tgl_bayar"]); 
                $modelSetoran->nik_wp = trim($_POST['Setoran']['nik_wp']);
                //$modelSetoran->no_rev = $_POST['Setoran']['no_rev'];
                $modelSetoran->jml_bayar = substr(str_replace('.', '', $_POST['Setoran']['jml_bayar']), 0, strlen(str_replace('.', '', $_POST['Setoran']['jml_bayar'])) - 3);
                $modelSetoran->kode_vib = 1;
                $modelSetoran->jenis_sk = $_POST['Setoran']['jenis_sk'];
                $modelSetoran->kd_propinsi = $_POST['Setoran']['kd_propinsi'];
                $modelSetoran->kd_dati2 = $_POST['Setoran']['kd_dati2'];
                $modelSetoran->kd_kecamatan = $_POST['Setoran']['kd_kecamatan'];
                $modelSetoran->kd_kelurahan = $_POST['Setoran']['kd_kelurahan'];
                $modelSetoran->kd_blok = $_POST['Setoran']['kd_blok'];
                $modelSetoran->no_urut = $_POST['Setoran']['no_urut'];
                $modelSetoran->kd_jns_op = $_POST['Setoran']['kd_jns_op'];
                $modelSetoran->sts = 1;

                $transaction = Yii::app()->db->beginTransaction();
                //$transaction->commit();
                try {


                    if ($modelSetoran->save()) {
                        
                        $transaction->commit();
                        Yii::app()->user->setFlash('success', '<strong>Selamat !!</strong> Data telah berhasil diupdate.');
                        $this->redirect(array('create',

                        ));

                    }

                    } catch (Exception $e) {
                    $transaction->rollback();
                    throw new CHttpException(404, $e->getMessage());
                }
            } 
            else {
                $modelInsertDatSubjekPajak = new DatSubjekPajak;

                $modelWajibPajak = new WajibPajak;

                $modelWajibPajak->subjek_pajak_id = trim($_POST['Setoran']['nik_wp']);
                $modelWajibPajak->nama_kec = $_POST['WajibPajak']['nama_kec'];

                $modelInsertDatSubjekPajak->subjek_pajak_id = trim($_POST['Setoran']['nik_wp']);
                $modelInsertDatSubjekPajak->nm_wp = $_POST['DatSubjekPajak']['nm_wp'];
                $modelInsertDatSubjekPajak->jalan_wp = $_POST['DatSubjekPajak']['jalan_wp'];
                $modelInsertDatSubjekPajak->blok_kav_no_wp = $_POST['DatSubjekPajak']['blok_kav_no_wp'];
                $modelInsertDatSubjekPajak->rt_wp = $_POST['DatSubjekPajak']['rt_wp'];
                $modelInsertDatSubjekPajak->rw_wp = $_POST['DatSubjekPajak']['rw_wp'];
                $modelInsertDatSubjekPajak->kd_pos_wp = $_POST['DatSubjekPajak']['kd_pos_wp'];
                $modelInsertDatSubjekPajak->kota_wp = $_POST['DatSubjekPajak']['kota_wp'];
                
                $modelSetoran->attributes=$_POST['Setoran'];
				$modelSetoran->kode_sptpd = 0;
                $modelSetoran->thn_pajak = $_POST['Setoran']['thn_pajak'];
                $modelSetoran->pajak_bphtb = 0;
                $modelSetoran->tgl_bayar =HelperUtils::tglToDb($_POST["Setoran"]["tgl_bayar"]); 
                $modelSetoran->nik_wp = trim($_POST['Setoran']['nik_wp']);
                //$modelSetoran->no_rev = $_POST['Setoran']['no_rev'];
                $modelSetoran->jml_bayar = substr(str_replace('.', '', $_POST['Setoran']['jml_bayar']), 0, strlen(str_replace('.', '', $_POST['Setoran']['jml_bayar'])) - 3);
                $modelSetoran->kode_vib = 1;
                $modelSetoran->jenis_sk = $_POST['Setoran']['jenis_sk'];
                $modelSetoran->kd_propinsi = $_POST['Setoran']['kd_propinsi'];
                $modelSetoran->kd_dati2 = $_POST['Setoran']['kd_dati2'];
                $modelSetoran->kd_kecamatan = $_POST['Setoran']['kd_kecamatan'];
                $modelSetoran->kd_kelurahan = $_POST['Setoran']['kd_kelurahan'];
                $modelSetoran->kd_blok = $_POST['Setoran']['kd_blok'];
                $modelSetoran->no_urut = $_POST['Setoran']['no_urut'];
                $modelSetoran->kd_jns_op = $_POST['Setoran']['kd_jns_op'];
                $modelSetoran->sts = 0;
                $transaction = Yii::app()->db->beginTransaction();
                
                try {
                    if ($modelSetoran->save() && $modelInsertDatSubjekPajak->save() && $modelWajibPajak->save()) {
						$transaction->commit();
						Yii::app()->user->setFlash('success', '<strong>Selamat !!</strong> Data telah berhasil diUpdate.');

                        $this->redirect(array('create'));
                    }
                } catch (Exception $e) {
                    $transaction->rollback();
                    throw new CHttpException(400, $e->getMessage());
                }
            }
        }
    
      
        $this->render('update', array(
            'model' => $model,
            'modelSetoran' => $modelSetoran,
            'modelWajibPajak' => $modelWajibPajak,
            'modelDatSubjekPajak' => $modelDatSubjekPajak,
            'modelSk'=>$modelSk,
        ));
    }

    public function actionDelete($id) {
        if (Yii::app()->request->isPostRequest) {
            $this->loadModel($id)->delete();
           if (!isset($_GET['ajax']))
                $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
        }
        else
            throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
    }

    
    public function actionAdmin() {
        $modelSetoran = new Setoran;
        $model = new ObjekPajak;
        
        $modelSetoran->unsetAttributes();  // clear any default values
        if (isset($_GET['Setoran']))
            $modelSetoran->attributes = $_GET['Setoran'];   
            $modelSetoran->nop = $_GET['Setoran']['nop'];
            $modelSetoran->nm_wp = $_GET['Setoran']['nm_wp'];
            
        $this->render('admin', array(
            'modelSetoran' => $modelSetoran,
            'model' => $model,
        ));

   }

    /**
     * Returns the data model based on the primary key given in the GET variable.
     * If the data model is not found, an HTTP exception will be raised.
     * @param integer the ID of the model to be loaded
     */
    
	public function loadModel($id){
		$sql 	= Setoran::model()->CariSetoranUpdateBank($id);
        $modelSetoran 	= Setoran::model()->find($sql);
        return $modelSetoran;
    }

    /**
     * Performs the AJAX validation.
     * @param CModel the model to be validated
     */
    protected function performAjaxValidation($model) {
        if (isset($_POST['ajax']) && $_POST['ajax'] === 'objek-pajak-form') {
            echo CActiveForm::validate($model);
            Yii::app()->end();
        }
    }

	public function actionVerifikasi(){
		$sql 	= DatObjekPajak::model()->searchVerifikasi($_POST["nop"]);
		$model 	= DatObjekPajak::model()->find($sql);
		$nilai 	= Nilai::model()->find();
        $this->renderPartial('verifikasi', array(
            'model' => $model,
			'nilai' => $nilai,
			'npopTkp' => $npopTkp
        ));
    }
}
